import 'package:get/get.dart';
import 'package:xinxuan/common/dialogs/message_dialog.dart';
import 'package:xinxuan/http/http_util_service.dart';
import 'package:xinxuan/utils/color_util.dart';
import 'package:xinxuan/vo/msg_vo.dart';
import 'package:xinxuan/vo/writeoff_vo.dart';

class WriteOffPageController extends GetxController {
  
  String code = '';

  var writeoffData = WriteoffData(id: 0, status: 8).obs;

  @override
  void onReady() {
    Map<String, dynamic> mapArguments = Get.arguments;
    code = mapArguments['code'];
    getWriteoffData();
    super.onReady();
  }

  /// 获取核销商品数据
  getWriteoffData() async {
    WriteoffVo writeoffVo =  await HttpUtilService.getWriteoffData(code: code);
    writeoffData.value = writeoffVo.data!;
    update();
  }

  /// 核销
  writeoff() async {
    MsgVo? msgData = await HttpUtilService.writeoffData(code: code);
    if (msgData != null) {
      Get.dialog(MessageDialog(
        message: msgData.data!.msg ?? '提示异常', 
        title: '提示信息',
        messageColor: textSubtitleColor,
      ));
    } else {
      getWriteoffData();
    }
  }
}